/*
* 按下回车键，另一个标签获得焦点
* */
function focusfunc(app,options){
    let number1 = -1
    function aaa(el,binding){
        const {arg,value} = binding;
        if(arg===value){
            const dom = el.querySelector("input") || el.querySelector("textarea") || el;
            dom.focus();
        }else{
            const dom = el.querySelector("input") || el.querySelector("textarea") || el;
            dom.blur();
        }

    }
    app.directive('focus', {
        beforeMount:function(el,binding){
            // 保存赋值的数字
            const {arg} = binding
            number1 = parseInt(arg)
        },
        mounted:function(el,binding){
            el.addEventListener("keydown",(e)=>{
                if(e.keyCode===13){
                    aaa(el,binding)
                }
            })
            // 挂载好就执行一次
            aaa(el,binding)
            el.addEventListener("focus",()=>{
                console.log("如何修改数据源")
            })
        },
        unmounted:function(el,binding){
            el.removeEventListener("keydown",(e)=>{
                if(e.keyCode===13){
                    aaa(el,binding)
                }
            })
            el.removeEventListener("focus",()=>{
                console.log("如何修改数据源")
            })
        },
    })
}

export default {
    install: focusfunc
}
